﻿using System.Windows.Forms;
using GeoSketch2.Core;

namespace GeoSketch2.Archaeo
{
    /// <summary> 
    /// The tool to create squares using polyline
    /// </summary>
    public class TExcavationSquareCreationPolyline:BaseArchaeoTool
    {
        #region Fields
        /// <summary> 
        /// The current polyline
        /// </summary>
        public Polyline CurrentPolyline;
        #endregion

        #region Constructor
        /// <summary> 
        /// The tool to draw Archaeo polylines
        /// </summary>
        /// <param name="Viewport">The viewport to draw to</param>
        public TExcavationSquareCreationPolyline(Viewport Viewport)
            : base(Viewport,"Square Creation")
        {
            NewPolyline();
        } 
        #endregion

        #region Inputs
        /// <summary>
        /// The method called when the mouse button is down
        /// </summary>
        public override void MouseDown(MouseEventArgs MouseArgs)
        {
            ExternalPointSent(Viewport.Object2ImageTransformation.InverseTransform(MouseArgs.Location));
        }

        /// <summary>
        /// The method called when a text is sent to the tool
        /// </summary>
        public override void TextEntry(string Text)
        {
            ExternalPointSent(GetCoordinatesFromString(Text));
        }

        /// <summary>
        /// The method called when a point in object coordinates is sent to the tool
        /// </summary>
        public override void ExternalPointSent(Point2D64D Point)
        {
            CurrentPolyline.Vertices.Add(new Vertex(Point, VertexType.Line));
            RefreshViewport();
        }
        #endregion

        #region Methods
        /// <summary>
        /// Creates a new polyline
        /// </summary>
        public void NewPolyline()
        {
            CurrentPolyline = new Polyline(null,null, null, Vars.Setup.Tools.TExcavationSquareCreation.LineType, Vars.Setup.Tools.TExcavationSquareCreation.LineColor);
        }

        /// <summary>
        /// Closes the current polyline
        /// </summary>
        public void ClosePolyline()
        {
            CurrentPolyline.Vertices.Add(CurrentPolyline.Vertices[0]);
        }

        /// <summary>
        /// Draw the graphics requested by the object
        /// </summary>
        public override void Draw()
        {
            CurrentPolyline.Draw(Viewport);
        }

        /// <summary>
        /// The method to be used to send the first message to the user, just after beeing selected
        /// </summary>
        public override void SendFirstMessage()
        {
            SendMessage("Click or enter the coordinates of the point defining the bounds of the area");
        }
        #endregion
    }
}